Repository navigation
csnode: don't keep an uncertain block's rewards when the trusted mask differs - #9
Merged
Merged
Conversation
… differs When a node's own last block turns out to be "uncertain" (its hash is not the one the network signed), BlockChain::storeBlock() fetches the canonical block. If testContentEqual() says the two have the same content, the node swaps it in place (deferredBlock_ = pool) without touching the wallet caches. testContentEqual() ignored the trusted mask (numberTrusted/realTrusted). That mask decides which confidants receive the block reward and the fees (WalletsCache::Updater: fundConfidantsWalletsWitnReward, fundConfidantsWalletsWithFee). So a trusted node that built block N with its own mask (e.g. a confidant whose stage-3 it lost marked as untrusted) kept the rewards and fees credited under that mask, while every other node credits them under the canonical mask. The difference is permanent and silent, and it accumulates on the wallets of frequent trusted nodes. This is a plausible source of the balance divergence that left nodes stuck at block 176'776'210 (a validator withdrawing its rewards was rejected by "graph validation" on nodes holding a lower balance). Include the trusted mask in the compared content. When it differs, storeBlock takes the existing "different content" branch: removeLastBlock() reverts the own block from the caches with its own mask, and the canonical block is then applied through the normal sync path. No protocol or consensus rule changes. testContentEqual() is made public so it can be unit-tested. Test: BlockChain.ContentEqualRequiresSameTrustedMask fails before the fix. nodetests: 119/119 pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # tests/csnode/blockchain_tests.cpp
EnzinoBB
added a commit
that referenced
this pull request
Nov 5, 2026
- setup-test: "tokens node" passes --node-key too. The wallet no longer takes the node's key from the current folder (wallet PR #7), and this wallet.toml says node_key = "off" (the answer was create), so "node" did not resolve and the {"error": ...} JSON ended in KeyError 'source'. The error is now asserted first. - setup.ps1: the command printed for later quotes only the arguments that need it (".\credits-wallet.exe --config wallet.toml account new main"), as setup.sh does; the test looks for "account new main". - both: the create option says the account is under the wallet password, one for every account, chosen with the first (wallet PRs #9/#10). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a node's own last block turns out to be "uncertain" (its hash is not the one the network signed),
BlockChain::storeBlock()fetches the canonical block. IftestContentEqual()says the content is the same, the node swaps it in place (deferredBlock_ = pool) without touching the wallet caches.testContentEqual()ignored the trusted mask (numberTrusted/realTrusted), which is exactly what decides which confidants receive the reward and the fees (fundConfidantsWalletsWitnReward,fundConfidantsWalletsWithFee). A trusted node that built block N with its own mask (e.g. a confidant whose stage-3 was lost locally, marked untrusted) kept the rewards credited under that mask, while every other node credits them under the canonical mask. The difference is permanent and silent, and it builds up on the wallets of frequent trusted nodes.This is a plausible cause of the balance divergence that left nodes stuck at block 176'776'210: a validator's reward withdrawal was rejected by graph validation on nodes holding a lower balance.
Fix (+2 lines in
blockchain.cpp)The trusted mask is now part of the compared content. When it differs,
storeBlocktakes the existing "different content" branch:removeLastBlock()reverts the node's own block from the caches with its own mask (a mirror operation), and the canonical block is then applied through normal sync. No protocol or consensus rule changes.testContentEqual()is made public so it can be unit-tested.Tests
BlockChain.ContentEqualRequiresSameTrustedMasknodetestsNotes
🤖 Generated with Claude Code